<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      columnsRef="testindex"
      selectionType="single"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :isSelectColumn="false"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
    >
    </FilterTable>

    <Drawer
      :visible.sync="visibleDrawer"
      title="配件时效性维护"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-modal v-model="initData" @close="infoClose" />
    </Drawer>
  </div>
</template>

<script>
import infoModal from './info';
import { dictionary } from '@/utils/dictMixin';
import { selectBasicData } from '@/api/partsmanage/partinfos/partParameter';
export default {
  name: 'chaimeffectivenessindex',
  components: {
    infoModal
  },
  mixins: [dictionary],
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchParams: {
        parentName: '索赔类型'
      },
      fetchApi: selectBasicData,
      initData: {},
      visibleDrawer: false
    }
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'SELECT',
          label: '索赔类型:',
          fieldName: 'name',
          placeholder: '请选择...',
          itemList: this.createDictList('5006')
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          fixed: 'left',
          render: props => {
            return (
              <div>
              <el-button size="mini" type="text" onClick={() => this.detailHandle(props.row, 'edit')}>
              维护
              </el-button>
            </div>
          );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '索赔类型',
          dataIndex: 'name',
          sorter: true,
          render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.name, '5006')}</span>;
          }
        },
        {
          title: '索赔时效(天)',
          dataIndex: 'value',
          placeholder: '天',
          sorter: true,
          // editType: 'number',
          // editRequired: true,
          // editable: true
        }
      ]
    },
    changeHandle(val) {
      // this.fetchParams = Object.assign({}, val);
      this.fetchParams = Object.assign({}, val, { parentName: '索赔类型', xhrAbort: false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectData(val) {
      this.tableData = val;
    },
    detailHandle(row,type) {
      this.initData =  {
        type: type,
        data: row,
        id:1001
      }; //行id
      this.visibleDrawer = true;
    },
    infoClose(rData) {
      this.visibleDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
}
</script>